package logic

import (
	"context"
	"gozerogateway/rpc/model/appmodel"
	"gozerogateway/rpc/tenant/internal/svc"
	"gozerogateway/rpc/tenant/tenantclient"

	"encoding/json"
	"github.com/zeromicro/go-zero/core/logx"
)

type AppDeleteLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewAppDeleteLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AppDeleteLogic {
	return &AppDeleteLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *AppDeleteLogic) AppDelete(in *tenantclient.AppDeleteReq) (*tenantclient.AppDelteResp, error) {
	// todo: add your logic here and delete this line

	err := l.svcCtx.AppModel.Update(l.ctx, &appmodel.GatewayApp{
		IsDelete: 0,
		Id:       in.ID,
	})
	if err != nil {
		reqStr, _ := json.Marshal(in)
		logx.WithContext(l.ctx).Errorf("delete app error,id error,param:%s", reqStr)
		return nil, err
	}
	return &tenantclient.AppDelteResp{}, nil
}
